#pragma once
#include "serialization.hpp"




int description(int& code,int x,int y,char op)
{
    switch(op)
    {
        case '+':
            return x + y;
        case '-':
            return x - y;
        case '*':
            return x*y;
        case '/':
            {
                if(y == 0)
                {
                    code = DivisionError;
                    return 0;
                }
                return x / y;
            }
        default:
            {
                code = FormatError;
                return 0;
            }
    }
}


std::string ComTask(std::string& s)
{
    std::string str = Unpack(s);
    auto& cpg = ContentPackage::Getinitance();
    cpg.Deserialization(str);
    int x = cpg.Getx();
    int y = cpg.Gety();
    char op = cpg.Getop();
    //计算
    int code = 0;
    int result = description(code,x,y,op);

    //序列化结果
    auto& rpg = ResultPackage::Getinitance();
    rpg.AddDate(result,code);
    str.clear();
    rpg.Serialization(str);

    //网络封装
    str = Package(str);
    return str;
}















